<template>
	<div class="page">
		<div class="paper">
			<div class="title">
				<div class="find">
					<el-input class="input" v-model="query.userName" placeholder="请输入内容" />
					<el-button plain style="background-color: #D3D3D3;" v-on:click="list()">查询</el-button>
					<el-button plain style=" background-color: slateblue; color: white;" @click="insert()">
						添加
					</el-button>
				</div>
			</div>
			<div class="fromTbale">
				<form>
					<el-table :data="MealData" style="width: 100%">
						<el-table-column type="index" label="编号" width="70">
						</el-table-column>
						<el-table-column prop="userName" label="客户姓名" width="100">
						</el-table-column>
						<el-table-column prop="sex" label="客户性别" width="100">
						</el-table-column>
						<el-table-column prop="age" label="年龄" width="100">
						</el-table-column>
						<el-table-column prop="hobby" label="平时喜好" width="200">
						</el-table-column>
						<el-table-column prop="announcements" label="注意事项" width="200">
						</el-table-column>
						<el-table-column prop="note" label="备注" width="200">
						</el-table-column>
						<el-table-column label="操作">
							<template slot-scope="scope">
								<el-button size="mini" @click="handleEdit(scope.row.mealsId)">编辑</el-button>
								<el-button size="mini" type="danger" @click="deleteById(scope.row.mealsId)">删除
								</el-button>
							</template>
						</el-table-column>
					</el-table>

					<el-pagination background layout="prev, pager, next" :total="total"
						:current-page.sync="query.current" :page-size="query.pageSize" @current-change="list()">
					</el-pagination>
				</form>
			</div>
			<el-dialog :title="title" :visible.sync="show" :close-on-click-modal="false" width="1000px">
				<MealEdit v-if="show" :show.sync="show" @getData="list()" :editid="editid"></MealEdit>
			</el-dialog>
		</div>
	</div>
</template>

<script>
	import MealEdit from '@/views/meals/edit';
	export default {
		name: 'Meals',
		data() {
			return {
				MealData: [],
				query: {
					userName: '',
					current: 1,
					pageSize: 5
				},
				total: 10,
				show: false,
				editid: null,
				title: ''
			}
		},
		methods: {
			list() {
				this.axios.get('/meals/list', eq => {
					this.MealData = eq.obj.records;
					this.query.current = eq.obj.current;
					this.total = eq.obj.total;
				}, this.query);
			},
			handleEdit(mealsId) {
				this.title = "修改";
				this.editid = mealsId;
				this.show = true;
			},
			insert() {
				this.title = "新增";
				this.editid = null;
				this.show = true;
			},
			deleteById(mealsId) {
				this.axios.del('/meals/delete?mealsId=' + mealsId, eq => {
					if (eq.obj) {
						this.$message({
							message: "删除成功",
							type: 'success'
						});
					} else {
						this.$message({
							message: '删除失败',
							type: 'error'
						});
					}
					this.list();
				})
			}
		},
		created() {
			this.list();
		},
		components: {
			MealEdit
		}
	}
</script>

<style>
	.page {
		color: #000000;
	}


	.paper {
		margin-left: 20px;
		margin-top: 20px;
		box-shadow: 7px 6px 5px lightgray;
		width: 100%;
	}

	.title {
		padding-bottom: 10px;
		border-bottom: 1px solid lightgray;
	}

	.title .find {
		display: flex;
		margin: 0px 10px;
	}

	.title span {
		margin: 0px 10px;
	}

	.addimg {
		width: 20px;
		height: 20px;

	}

	.title .find .input {
		width: 20%;
	}

	.fromTbale {
		margin-top: 20px;
	}
</style>
